-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make PIO IRQ IDs into ZSTs #723
Conversation
Hello, thank you for the contribution. |
This allows me to write a module which uses PIO while being generic over the IRQ it uses. See https://github.com/redolution/cubane/blob/e35d1be482b2e81d074fc699efcec44f840ab4f3/src/exi.rs, in particular these two lines:
I can't use a match block over the const generic here because the two IRQs have different type signatures, type-level selection is the only option as far as I can tell. I admit the commit/PR message is a bit lacking, I was very frustrated about not getting this to work so I didn't really have the energy to write a better one. |
I see, thank you :) Only adding |
Yup, hence I implemented the same construct as is already used for things like state machine and DMA channel IDs. |
Actually I found a way to check for that that's transparent to the user: pub fn irq<const IRQ: usize>(&self) -> Interrupt<'_, P, IRQ> {
struct IRQSanity<const X: usize>;
impl<const IRQ: usize> IRQSanity<IRQ> {
const CHECK: () = assert!(IRQ == 0 || IRQ == 1, "Irq Index must be either 0 or 1");
}
let _test = IRQSanity::<IRQ>::CHECK;
Interrupt {
block: self.pio.deref(),
_phantom: core::marker::PhantomData,
}
} The error message looking like:
|
Oh that's neat, although the error message is a bit weird. |
This allows writing modules that are generic over the IRQ. Co-authored-by: Wilfried Chauveau <[email protected]>
Updated with your suggestion, so this is no longer a breaking change. |
This allows getting the IRQ with
pio.irq::<IRQn>()
, where IRQn is a type generic.This is a minor breaking change. I struggled for a while trying to get something similar working with the existing const generic, without success.